package cn.iocoder.yudao.module.famous.doctor.dal.mysql.inquiry;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.forum.FamForumDO;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.inquiry.InquiryDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.famous.doctor.controller.admin.inquiry.vo.*;
import org.apache.ibatis.annotations.Param;

import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * 我的问诊 Mapper
 *
 * @author Test1
 */
@Mapper
public interface InquiryMapper extends BaseMapperX<InquiryDO> {

    default PageResult<InquiryDO> selectPage(InquiryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InquiryDO>()
                .eqIfPresent(InquiryDO::getSymptom, reqVO.getSymptom())
                .eqIfPresent(InquiryDO::getHistory, reqVO.getHistory())
                .eqIfPresent(InquiryDO::getAllergy, reqVO.getAllergy())
                .eqIfPresent(InquiryDO::getPhysical, reqVO.getPhysical())
                .eqIfPresent(InquiryDO::getPhysicalBottom, reqVO.getPhysicalBottom())
                .eqIfPresent(InquiryDO::getOthers, reqVO.getOthers())
                .betweenIfPresent(InquiryDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(InquiryDO::getDockerId, reqVO.getDockerId())
                .betweenIfPresent(InquiryDO::getSustainTime, reqVO.getSustainTime())
                .eqIfPresent(InquiryDO::getIdentityCard, reqVO.getIdentityCard())
                .eqIfPresent(InquiryDO::getIllnessDescribe, reqVO.getIllnessDescribe())
                .eqIfPresent(InquiryDO::getFormId, reqVO.getFormId())
                .eqIfPresent(InquiryDO::getDiagnoseLabel, reqVO.getDiagnoseLabel())
                .eqIfPresent(InquiryDO::getImprove, reqVO.getImprove())
                .eq(InquiryDO::getCreator, getLoginUserId())
                .orderByDesc(InquiryDO::getId));
    }

    default List<InquiryDO> selectList(InquiryExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<InquiryDO>()
                .eqIfPresent(InquiryDO::getSymptom, reqVO.getSymptom())
                .eqIfPresent(InquiryDO::getHistory, reqVO.getHistory())
                .eqIfPresent(InquiryDO::getAllergy, reqVO.getAllergy())
                .eqIfPresent(InquiryDO::getPhysical, reqVO.getPhysical())
                .eqIfPresent(InquiryDO::getPhysicalBottom, reqVO.getPhysicalBottom())
                .eqIfPresent(InquiryDO::getOthers, reqVO.getOthers())
                .betweenIfPresent(InquiryDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(InquiryDO::getDockerId, reqVO.getDockerId())
                .betweenIfPresent(InquiryDO::getSustainTime, reqVO.getSustainTime())
                .eqIfPresent(InquiryDO::getIdentityCard, reqVO.getIdentityCard())
                .eqIfPresent(InquiryDO::getIllnessDescribe, reqVO.getIllnessDescribe())
                .eqIfPresent(InquiryDO::getFormId, reqVO.getFormId())
                .eqIfPresent(InquiryDO::getDiagnoseLabel, reqVO.getDiagnoseLabel())
                .eqIfPresent(InquiryDO::getImprove, reqVO.getImprove())
                .eq(InquiryDO::getCreator, getLoginUserId())
                .orderByDesc(InquiryDO::getId));
    }

    default InquiryDO selectOne(InquiryReqLabelVO reqVO) {
        InquiryDO inquiryDO = selectOne(new LambdaQueryWrapperX<InquiryDO>()
                .eq(InquiryDO::getCreator, getLoginUserId())
                .eqIfPresent(InquiryDO::getIdentityCard, reqVO.getIdentityCard())
                .eqIfPresent(InquiryDO::getDiagnoseLabel, reqVO.getDiagnoseLabel())
                .orderByDesc(InquiryDO::getCreateTime)
                .last("limit 1"));
        return inquiryDO;
    }

    default PageResult<InquiryDO> getIoutpatientList(InquiryPageReqVO reqVO){
        return selectPage(reqVO, new LambdaQueryWrapperX<InquiryDO>()
                .eqIfPresent(InquiryDO::getSymptom, reqVO.getSymptom())
                .eqIfPresent(InquiryDO::getHistory, reqVO.getHistory())
                .eqIfPresent(InquiryDO::getAllergy, reqVO.getAllergy())
                .eqIfPresent(InquiryDO::getPhysical, reqVO.getPhysical())
                .eqIfPresent(InquiryDO::getPhysicalBottom, reqVO.getPhysicalBottom())
                .eqIfPresent(InquiryDO::getOthers, reqVO.getOthers())
                .betweenIfPresent(InquiryDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(InquiryDO::getDockerId, getLoginUserId())
                .betweenIfPresent(InquiryDO::getSustainTime, reqVO.getSustainTime())
                .eqIfPresent(InquiryDO::getIdentityCard, reqVO.getIdentityCard())
                .eqIfPresent(InquiryDO::getIllnessDescribe, reqVO.getIllnessDescribe())
                .eqIfPresent(InquiryDO::getFormId, reqVO.getFormId())
                .eqIfPresent(InquiryDO::getDiagnoseLabel, reqVO.getDiagnoseLabel())
                .eqIfPresent(InquiryDO::getImprove, reqVO.getImprove())
                .orderByDesc(InquiryDO::getId));
    }

    IPage<InquiryMyPatientRespVO> getMyPatient(Page<Object> objectPage, @Param("userId") Long loginUserId,@Param("param")  InquiryMyPatientPageReqVO pageVO);

    List<Long> selectAllFormByUserid(@Param("userId") String creator);
    List<InquiryMyPatientRespVO> selectAllFormByUserids(@Param("userId") String creator,@Param("identityCard")  String identityCard);
}
